/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.gui.query;

import com.google.gwt.user.client.rpc.IsSerializable;
import java.util.Vector;

public class QuerySummary implements IsSerializable  {
	
	public String queryID = "";
	public int count = -1;
	public int status = -1;
	public String note = "";
	public String ts = "";
	
	private Vector<Integer> types = new Vector<Integer>();
	private Vector<Integer> counts = new Vector<Integer>();
	
    public String[] columnAlignment;
    public String[] columnName;
    
    
	public QuerySummary() {
		
	}
	
	public void setTypeCount(int type, int count) {
		for (int i = 0; i < types.size(); i++) {
			int val = ((Integer)types.elementAt(i)).intValue();
			if (val == type) {
				counts.setElementAt(new Integer(count), i);
				return;
			}
		}
		types.addElement(new Integer(type));
		counts.addElement(new Integer(count));
	}
	
	public int getTypeCount(int type) {
		for (int i = 0; i < types.size(); i++) {
			int val = types.elementAt(i);
			if (val == type) {
				return counts.elementAt(i);
			}
		}
		return -1; // type not specified in the query 
	}
	
	public String toXML() {
	    StringBuilder temp = new StringBuilder("<SearchResult");
	    temp.append(" queryid=\"" + queryID + "\"");
	    temp.append(" status=\"" + status + "\"");
	    temp.append(" timestamp=\"" + ts + "\"");
	    temp.append(" count=\"" + count + "\"");
	    temp.append(">");
        if (types != null) {
	        for (int i = 0;  i < types.size(); i++) {
	            temp.append("<Type id=\"" + types.elementAt(i) + "\" count=\"" + counts.elementAt(i) + "\"/>");
	        }
	    }
        temp.append("</SearchResult>");
	    return temp.toString();
	}

}
